package acwing;

import java.util.Scanner;

/**
 * ClassName: $785_quicksort
 * Description:
 * date: 2021/9/11 15:35
 *
 * @author liyifan
 */
public class $785_quicksort {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        int[] nums = new int[N];
        for(int i = 0; i < N; i++) {
            nums[i] = scanner.nextInt();
        }

        quick_sort(nums, 0, N - 1);

        for(int i = 0;i < nums.length;i++){
            if (i != nums.length - 1) {
                System.out.print(nums[i] + " ");
            } else {
                System.out.println(nums[i]);
            }
        }

    }

    public static void quick_sort(int nums[], int l, int r) {
        if(l >= r)
            return;
        int i = l - 1, j = r + 1, x = nums[l + r >> 1];
        while (i < j) {
            do {
                i++;
            } while (nums[i] < x);
            do {
                j--;
            } while (nums[j] > x);
            if (i < j){
                int temp = nums[i];
                nums[i] = nums[j];
                nums[j] = temp;
            }
        }
        quick_sort(nums, l, j);
        quick_sort(nums, j + 1, r);
    }
}
